﻿using System.Collections.Generic;
using YanZhiwei.DotNet2.Utilities.Base;
namespace YanZhiwei.DotNet2.Utilities.Common
{
    /// <summary>
    /// Enumerable 帮助类
    /// </summary>
    public static class IEnumerableHelper
    {
        #region 线程安全【上锁】
        /// <summary>
        /// 线程安全【上锁】
        ///<para> eg: foreach(var item in someList.AsLocked(someLock))</para>
        ///<para> 参考:http://www.codeproject.com/Articles/56575/Thread-safe-enumeration-in-C </para>
        /// </summary>
        /// <typeparam name="T">泛型</typeparam>
        /// <param name="ie">IEnumerable</param>
        /// <param name="lock">lock对象</param>
        /// <returns>IEnumerable</returns>
        public static IEnumerable<T> AsLocked<T>(this IEnumerable<T> ie, object @lock)
        {
            return new ThreadSafeEnumerableHelper<T>(ie, @lock);
        }
        #endregion 

    }
}